package com.guijq.design.practice.one;

import java.util.function.Consumer;

public class Box {

    protected int money;

    public Box(int innermoney) {
        this.money = innermoney;
    }

    protected <T extends Role> Consumer<Role> getRoleBehavior(Class<T> roleClass) {
        return role -> {
            role.money += this.money;
        };
    }

    public void beOpenBy(Role role) {
        if (null == getRoleBehavior(role.getClass())) {
            throw new RuntimeException("盒子不支持该类型人员打开");
        }
        getRoleBehavior(role.getClass()).accept(role);
        this.money = 0;
    }

    public void facade() {
        System.out.println("这是一个宝箱");
    }


}
